using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using OneSoft.EntityCore;
using OneSoft.DataAccess;
using BySoft.Server.Common.Entity;
using BySoft.Server.Common.Schema;
using BySoft.Server.DataAccess;

namespace BySoft.Server.Business
{
	/// <summary>
	/// MdSupplier
	/// </summary>
	public partial class MdSupplier
	{
		#region GetByID
		/// <summary>
		/// 取得实体
		/// </summary>
		/// <param name="id">实体关键字</param>
		/// <returns>实体实例</returns>
		public static MdSupplierEntity GetMdSupplierByID(String id)
		{
			return MdSupplierDA.GetMdSupplierByID(id);
		}
		#endregion

		#region Insert
		/// <summary>
		/// 插入数据
		/// </summary>
		/// <param name="objMdSupplierEntity">实体实例</param>
		/// <returns>true 插入成功; false 插入失败</returns>
		public static bool InsertMdSupplier(MdSupplierEntity objMdSupplierEntity)
		{
			if (objMdSupplierEntity == null)
			{
				return false;
			}
			try
			{
				
				return OneSoft.DataAccess.DataAccessCommon.Insert(objMdSupplierEntity);

				
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		#endregion

		#region Update
		/// <summary>
		/// 更新数据
		/// </summary>
		/// <param name="objMdSupplierEntity">实体实例</param>
		/// <returns>true 更新成功; false 更新失败</returns>
		public static bool UpdateMdSupplier(MdSupplierEntity objMdSupplierEntity)
		{
			if (objMdSupplierEntity == null)
			{
				return false;
			}
			try
			{
				return OneSoft.DataAccess.DataAccessCommon.Update(objMdSupplierEntity);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		#endregion

		#region Delete
		/// <summary>
		/// 删除数据
		/// </summary>
		/// <param name="objMdSupplierEntity">实体实例</param>
		/// <returns>true 删除成功; false 删除失败</returns>
		public static bool DeleteMdSupplier(MdSupplierEntity objMdSupplierEntity)
		{
			if (objMdSupplierEntity == null)
			{
				return false;
			}
			try
			{
				return OneSoft.DataAccess.DataAccessCommon.Delete(objMdSupplierEntity);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		#endregion

		#region GetAll
		/// <summary>
		/// 获取所有数据
		/// </summary>
		/// <returns>返回所有数据</returns>
		public static DataSet GetMdSupplierAll()
		{
			try
			{
				return MdSupplierDA.GetMdSupplierAll();
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		#endregion

		#region GetDSByCondition
		/// <summary>
		/// 获取符合条件的DS
		/// </summary>
		/// <returns>返回DS</returns>
		public static DataSet GetDSByCondition(string strCondition)
		{
			try
			{
				return MdSupplierDA.GetDSByCondition(strCondition);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		#endregion

		#region GetByCondition
		/// <summary>
		/// 获取符合条件的数据实体
		/// </summary>
		/// <returns>返回数据实体</returns>
		public static List<MdSupplierEntity> GetByCondition(string strCondition)
		{
			try
			{
				return MdSupplierDA.GetByCondition(strCondition);
			}
			catch (Exception ex)
			{
				throw ex;
			}
		}
		#endregion

        public static void Del(string strCode)
        {
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    broker.BeginTransaction();
                    ClsCommDA.Del("MD_Supplier", "SupplierID", strCode, broker);
                    broker.Commit();
                }
                catch
                {
                    broker.Rollback();
                    throw;
                }
            }
        }

        public static DataTable SelectList(string SupplierID, string SupplierName, string SupplierScaler, int pageIndex, int PageSize, out int m_count)
        {
            return MdSupplierDA.SelectList(SupplierID,SupplierName,SupplierScaler,pageIndex,PageSize,out m_count);
        }

        public static bool CheckSupplierNameIsExists(string SupplierName, string SupplierID)
        {
            return MdSupplierDA.CheckSupplierNameIsExists(SupplierName, SupplierID);
        }

        public static bool SaveMdSupplierEntity(MdSupplierEntity entity)
        {
            bool isResult = true;
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    DataAccessCommon.Insert(entity, broker);
                    broker.Commit();
                }
                catch (Exception ex)
                {
                    isResult = false;
                    broker.Rollback();
                    throw ex;
                }

            }
            return isResult;
        }

        public static bool Update(MdSupplierEntity entity)
        {
            bool isResult = true;
            using (DataAccessBroker broker = DataAccessFactory.Instance())
            {
                try
                {
                    DataAccessCommon.Update(entity, broker);
                    broker.Commit();
                }
                catch (Exception ex)
                {
                    isResult = false;
                    broker.Rollback();
                    throw ex;
                }

            }
            return isResult;
        }

        public static DataTable SelectDialogList(string SupplierID, string SupplierName, string MaterialID, int pageIndex, int PageSize, out int m_count)
        {
            return MdSupplierDA.SelectDialogList(SupplierID, SupplierName, MaterialID, pageIndex, PageSize, out m_count);
        }

      

    }

}
